<!-- HTML header for doxygen 1.8.6-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<title>OpenCV: samples/cpp/cout_mat.cpp</title>
<link href="../../opencv.ico" rel="shortcut icon" type="image/x-icon" />
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../jquery.js"></script>
<script type="text/javascript" src="../../dynsections.js"></script>
<script type="text/javascript" src="../../tutorial-utils.js"></script>
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../search/searchdata.js"></script>
<script type="text/javascript" src="../../search/search.js"></script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
    jax: ["input/TeX","output/HTML-CSS"],
});
//<![CDATA[
MathJax.Hub.Config(
{
  TeX: {
      Macros: {
          matTT: [ "\\[ \\left|\\begin{array}{ccc} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{array}\\right| \\]", 9],
          fork: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ \\end{array} \\right.", 4],
          forkthree: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ \\end{array} \\right.", 6],
          forkfour: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ #7 & \\mbox{#8}\\\\ \\end{array} \\right.", 8],
          vecthree: ["\\begin{bmatrix} #1\\\\ #2\\\\ #3 \\end{bmatrix}", 3],
          vecthreethree: ["\\begin{bmatrix} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{bmatrix}", 9],
          cameramatrix: ["#1 = \\begin{bmatrix} f_x & 0 & c_x\\\\ 0 & f_y & c_y\\\\ 0 & 0 & 1 \\end{bmatrix}", 1],
          distcoeffs: ["(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \\tau_x, \\tau_y]]]]) \\text{ of 4, 5, 8, 12 or 14 elements}"],
          distcoeffsfisheye: ["(k_1, k_2, k_3, k_4)"],
          hdotsfor: ["\\dots", 1],
          mathbbm: ["\\mathbb{#1}", 1],
          bordermatrix: ["\\matrix{#1}", 1]
      }
  }
}
);
//]]>
</script><script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js"></script>
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
<link href="../../stylesheet.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<!--#include virtual="/google-search.html"-->
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="../../opencv-logo-small.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">OpenCV
   &#160;<span id="projectnumber">4.5.2</span>
   </div>
   <div id="projectbrief">Open Source Computer Vision</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "../../search",false,'Search');
</script>
<script type="text/javascript" src="../../menudata.js"></script>
<script type="text/javascript" src="../../menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('../../',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">samples/cpp/cout_mat.cpp</div>  </div>
</div><!--header-->
<div class="contents">
<p>An example demonstrating the serial out capabilities of <a class="el" href="../../d3/d63/classcv_1_1Mat.html" title="n-dimensional dense array class ">cv::Mat</a></p>
<div class="fragment"><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * cvout_sample just demonstrates the serial out capabilities of cv::Mat</span></div><div class="line"><span class="comment"> *  That is, cv::Mat M(...); cout &lt;&lt; M;  Now works.</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> */</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &quot;<a class="code" href="../../d0/d9c/core_2include_2opencv2_2core_8hpp.html">opencv2/core.hpp</a>&quot;</span></div><div class="line"><span class="preprocessor">#include &lt;iostream&gt;</span></div><div class="line"></div><div class="line"><span class="keyword">using namespace </span><a class="code" href="../../d8/dcc/namespacestd.html">std</a>;</div><div class="line"><span class="keyword">using namespace </span><a class="code" href="../../d2/d75/namespacecv.html">cv</a>;</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span> help(<span class="keywordtype">char</span>** argv)</div><div class="line">{</div><div class="line">    cout</div><div class="line">    &lt;&lt; <span class="stringliteral">&quot;\n------------------------------------------------------------------\n&quot;</span></div><div class="line">    &lt;&lt; <span class="stringliteral">&quot; This program shows the serial out capabilities of cv::Mat\n&quot;</span></div><div class="line">    &lt;&lt; <span class="stringliteral">&quot;That is, cv::Mat M(...); cout &lt;&lt; M;  Now works.\n&quot;</span></div><div class="line">    &lt;&lt; <span class="stringliteral">&quot;Output can be formatted to OpenCV, matlab, python, numpy, csv and \n&quot;</span></div><div class="line">    &lt;&lt; <span class="stringliteral">&quot;C styles Usage:\n&quot;</span></div><div class="line">    &lt;&lt; argv[0]</div><div class="line">    &lt;&lt; <span class="stringliteral">&quot;\n------------------------------------------------------------------\n\n&quot;</span></div><div class="line">    &lt;&lt; endl;</div><div class="line">}</div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>** argv)</div><div class="line">{</div><div class="line">    <a name="_a0"></a><a class="code" href="../../d0/d2e/classcv_1_1CommandLineParser.html">cv::CommandLineParser</a> parser(argc, argv, <span class="stringliteral">&quot;{help h||}&quot;</span>);</div><div class="line">    <span class="keywordflow">if</span> (parser.<a name="a1"></a><a class="code" href="../../d0/d2e/classcv_1_1CommandLineParser.html#a8c41cf242b2ad8c0472e3b57893ef200">has</a>(<span class="stringliteral">&quot;help&quot;</span>))</div><div class="line">    {</div><div class="line">        help(argv);</div><div class="line">        <span class="keywordflow">return</span> 0;</div><div class="line">    }</div><div class="line">    <a name="_a2"></a><a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> I = Mat::eye(4, 4, <a name="a3"></a><a class="code" href="../../d1/d1b/group__core__hal__interface.html#ga30a562691cc5987bc88eb7bb7a8faf2b">CV_64F</a>);</div><div class="line">    I.<a name="a4"></a><a class="code" href="../../d3/d63/classcv_1_1Mat.html#aa5d20fc86d41d59e4d71ae93daee9726">at</a>&lt;<span class="keywordtype">double</span>&gt;(1,1) = <a name="a5"></a><a class="code" href="../../db/de0/group__core__utils.html#ga677b89fae9308b340ddaebf0dba8455f">CV_PI</a>;</div><div class="line">    cout &lt;&lt; <span class="stringliteral">&quot;I = \n&quot;</span> &lt;&lt; I &lt;&lt; <span class="stringliteral">&quot;;&quot;</span> &lt;&lt; endl &lt;&lt; endl;</div><div class="line"></div><div class="line">    <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> r = <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a>(10, 3, <a name="a6"></a><a class="code" href="../../d1/d1b/group__core__hal__interface.html#ga88c4cd9de76f678f33928ef1e3f96047">CV_8UC3</a>);</div><div class="line">    <a name="a7"></a><a class="code" href="../../d2/de8/group__core__array.html#ga1ba1026dca0807b27057ba6a49d258c0">randu</a>(r, Scalar::all(0), Scalar::all(255));</div><div class="line"></div><div class="line">    cout &lt;&lt; <span class="stringliteral">&quot;r (default) = \n&quot;</span> &lt;&lt; r &lt;&lt; <span class="stringliteral">&quot;;&quot;</span> &lt;&lt; endl &lt;&lt; endl;</div><div class="line">    cout &lt;&lt; <span class="stringliteral">&quot;r (matlab) = \n&quot;</span> &lt;&lt; format(r, Formatter::FMT_MATLAB) &lt;&lt; <span class="stringliteral">&quot;;&quot;</span> &lt;&lt; endl &lt;&lt; endl;</div><div class="line">    cout &lt;&lt; <span class="stringliteral">&quot;r (python) = \n&quot;</span> &lt;&lt; format(r, Formatter::FMT_PYTHON) &lt;&lt; <span class="stringliteral">&quot;;&quot;</span> &lt;&lt; endl &lt;&lt; endl;</div><div class="line">    cout &lt;&lt; <span class="stringliteral">&quot;r (numpy) = \n&quot;</span> &lt;&lt; format(r, Formatter::FMT_NUMPY) &lt;&lt; <span class="stringliteral">&quot;;&quot;</span> &lt;&lt; endl &lt;&lt; endl;</div><div class="line">    cout &lt;&lt; <span class="stringliteral">&quot;r (csv) = \n&quot;</span> &lt;&lt; format(r, Formatter::FMT_CSV) &lt;&lt; <span class="stringliteral">&quot;;&quot;</span> &lt;&lt; endl &lt;&lt; endl;</div><div class="line">    cout &lt;&lt; <span class="stringliteral">&quot;r (c) = \n&quot;</span> &lt;&lt; format(r, Formatter::FMT_C) &lt;&lt; <span class="stringliteral">&quot;;&quot;</span> &lt;&lt; endl &lt;&lt; endl;</div><div class="line"></div><div class="line">    <a name="_a8"></a><a class="code" href="../../db/d4e/classcv_1_1Point__.html">Point2f</a> p(5, 1);</div><div class="line">    cout &lt;&lt; <span class="stringliteral">&quot;p = &quot;</span> &lt;&lt; p &lt;&lt; <span class="stringliteral">&quot;;&quot;</span> &lt;&lt; endl;</div><div class="line"></div><div class="line">    <a name="_a9"></a><a class="code" href="../../df/d6c/classcv_1_1Point3__.html">Point3f</a> p3f(2, 6, 7);</div><div class="line">    cout &lt;&lt; <span class="stringliteral">&quot;p3f = &quot;</span> &lt;&lt; p3f &lt;&lt; <span class="stringliteral">&quot;;&quot;</span> &lt;&lt; endl;</div><div class="line"></div><div class="line">    vector&lt;float&gt; v;</div><div class="line">    v.push_back(1);</div><div class="line">    v.push_back(2);</div><div class="line">    v.push_back(3);</div><div class="line"></div><div class="line">    cout &lt;&lt; <span class="stringliteral">&quot;shortvec = &quot;</span> &lt;&lt; <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a>(v) &lt;&lt; endl;</div><div class="line"></div><div class="line">    vector&lt;Point2f&gt; points(20);</div><div class="line">    <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> i = 0; i &lt; points.size(); ++i)</div><div class="line">        points[i] = <a name="a10"></a><a class="code" href="../../dc/d84/group__core__basic.html#ga7d080aa40de011e4410bca63385ffe2a">Point2f</a>((<span class="keywordtype">float</span>)(i * 5), (<span class="keywordtype">float</span>)(i % 7));</div><div class="line"></div><div class="line">    cout &lt;&lt; <span class="stringliteral">&quot;points = &quot;</span> &lt;&lt; points &lt;&lt; <span class="stringliteral">&quot;;&quot;</span> &lt;&lt; endl;</div><div class="line">    <span class="keywordflow">return</span> 0;</div><div class="line">}</div></div><!-- fragment --> </div><!-- contents -->
<!-- HTML footer for doxygen 1.8.6-->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Fri Apr 2 2021 11:36:29 for OpenCV by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="../../doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
<script type="text/javascript">
//<![CDATA[
addTutorialsButtons();
//]]>
</script>
</body>
</html>
